
import serial

BUFFER_LEN = 1024

class SCPI():
    def __init__(self, port, baudrate=9600, stop=1):
        self.com = serial.Serial(port, baudrate=baudrate, timeout=1, stopbits=stop)

    def send(self, cmd):
        if not cmd.endswith("\n"):
            cmd += "\n"
        self.com.write(cmd.encode())
        echo = self.com.read(BUFFER_LEN)
        try:
            echo = echo.decode()
        except:
            pass
        return echo

    def close(self):
        self.com.close()
